/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cinescope2014.essais;

import java.util.HashMap;
import java.util.Map;
import javax.swing.DefaultCellEditor;
import javax.swing.JComboBox;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableColumn;

/**
 *
 * @author pascal
 */
public class Table7QuaterJCombo extends javax.swing.JFrame {

    private DefaultTableModel idtmVilles;
//    private JComboBox jcbxPays;
    private Map imapPays;

    /**
     * Creates new form Table7QuaterJCombo
     */
    public Table7QuaterJCombo() {

        super("Table7QuaterJCombo");
        initComponents();
        setLocationRelativeTo(null);

        imapPays = new HashMap();
        imapPays.put("France", "33");
        imapPays.put("Italie", "39");
        imapPays.put("Espagne", "35");

        idtmVilles = (DefaultTableModel) jTableVilles.getModel();

        /*
         * LA COLONNE SPECIALE (APRES LE REMPLISSAGE DE LA JTABLE)
         */
        // Declaree ici ou en tant qu'attribut
        JComboBox jcbxPays = new JComboBox();
        // Ajout d'items
        jcbxPays.addItem("France");
        jcbxPays.addItem("Italie");
        jcbxPays.addItem("Espagne");

        TableColumn tableColonnePays = jTableVilles.getColumnModel().getColumn(2);

        TableCellEditor tableCelluleEditeur = new DefaultCellEditor(jcbxPays);
        tableColonnePays.setCellEditor(tableCelluleEditeur);

        // Largeur de la colonne de la JTable
        tableColonnePays.setPreferredWidth(300);

        setVisible(true);
    } /// CONSTRUCTEUR

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTableVilles = new javax.swing.JTable();
        jButtonTester = new javax.swing.JButton();
        jLabelMessage = new javax.swing.JLabel();
        jButtonPlus = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTableVilles.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null}
            },
            new String [] {
                "CP", "Nom ville", "ID pays"
            }
        ));
        jScrollPane1.setViewportView(jTableVilles);

        jButtonTester.setText("Tester");
        jButtonTester.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonTesterActionPerformed(evt);
            }
        });

        jLabelMessage.setText("Message");

        jButtonPlus.setText("+");
        jButtonPlus.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonPlusActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 608, Short.MAX_VALUE)
                    .addComponent(jLabelMessage, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButtonTester, javax.swing.GroupLayout.PREFERRED_SIZE, 191, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonPlus)
                .addContainerGap(101, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 275, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jButtonPlus)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButtonTester)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabelMessage)
                .addContainerGap(15, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonPlusActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonPlusActionPerformed
        // TODO add your handling code here:
        String[] tLigne = new String[3];
        idtmVilles.addRow(tLigne);
    }//GEN-LAST:event_jButtonPlusActionPerformed

    private void jButtonTesterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonTesterActionPerformed
        // TODO add your handling code here:
        for (int i = 0; i < jTableVilles.getRowCount(); i++) {
            System.out.println("Valeur : " + jTableVilles.getValueAt(i, 2) + " : " + imapPays.get(jTableVilles.getValueAt(i, 2)));
        }
    }//GEN-LAST:event_jButtonTesterActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Table7QuaterJCombo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Table7QuaterJCombo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Table7QuaterJCombo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Table7QuaterJCombo.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new Table7QuaterJCombo().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonPlus;
    private javax.swing.JButton jButtonTester;
    private javax.swing.JLabel jLabelMessage;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTableVilles;
    // End of variables declaration//GEN-END:variables
}
